const mongoose = require('./db')
var Schema = mongoose.Schema

// // 好友表
// 当你们俩开始聊天之后把对方添加到这个表中
const FriendSchema = mongoose.Schema({
    userId: {
        type: mongoose.Types.ObjectId,  // 用户id
        ref: 'user'
    },
    friendId: {
        type: mongoose.Types.ObjectId,  //好友id
        ref: 'user'
    },
    time: {
        type: Date,   //生成时间
    },
    lastTime: {
        type: Date,   //最后消息时间
    }
});

const FriendModel = mongoose.model("Friend", FriendSchema, "Friend");

// 消息表
const MessageSchema = mongoose.Schema({
    userId: {
        type: mongoose.Types.ObjectId,  // 用户id
        ref: 'user'
    },
    friendId: {
        type: mongoose.Types.ObjectId,  //接收者id
        ref: 'user'
    },
    message: {
        type: String,      // 内容
    },
    types: {
        type: String,      // 内容类型（0文字，1图片链接，2音频,3地图位置）
    },
    time: {
        type: Date,       //发送时间
    },
    state: {
        type: Number,    // 消息状态（0已读，1未读）
    }
});
const MessageModel = mongoose.model("Message", MessageSchema, "Message");



// 门店管理
const ShopSchema = Schema({
    name: String,
    address: String,
    depict: String,
    longitude: {
        type: Number,
        default: null
    },
    latitude: {
        type: Number,
        default: null
    }
})

const ShopModel = mongoose.model('shop', ShopSchema, 'shop')

// 接单管理
const OrderSchema = Schema({
    orderTime: String,
    orderLength: String,
    home: String,
    longitude: {
        type: Number,
        default: null
    },
    latitude: {
        type: Number,
        default: null
    }
})

const OrderModel = mongoose.model('order', OrderSchema, 'order')


module.exports = {
    ShopModel, OrderModel, MessageModel, FriendModel
}
